<?php
/**
 * YouNet
 *
 * @category   Application_Extensions
 * @package    Adv Notification
 * @copyright  Copyright 2011 YouNet Developments
 * @license    http://www.modules2buy.com/
 * @version    $Id: menu auctions
 * @author     Minh Nguyen
 */
class Advmenusystem_Widget_AdvmenuMainController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
        $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
        $this->view->navigation = $navigation = Engine_Api::_()
          ->getApi('menus', 'advmenusystem')
          ->getNavigation('core_main');
        $require_check = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.general.browse', 1);
        if(!$require_check && !$viewer->getIdentity()){
          $page	= $navigation->findOneBy('route','user_general');
		  $this->hiddenBrowseMembers($navigation, $page);
          //$navigation->removePage($navigation->findOneBy('route','user_general'));
        }
        
        $this->view->controller = $this;
  }
  public function hiddenBrowseMembers($navigation, $page)
  {
  		$flag = false;	
  		foreach($navigation as $nav)
  		{
  			if($flag == true && !$nav->submenu)
			{
				$flag = false;
			}
  			if($nav->route == 'user_general')
  			{
  				$flag = true;
				$navigation->removePage($page);
  			}
			if($flag == true && $nav->submenu)
			{
				$navigation->removePage($nav);
			}
  		}
	}
}